package com.peakmain.wanandroid.mymodule.animation;

import android.util.Log;
import android.view.View;

/**
 * @author ：Peakmain
 * version ：1.0
 * createTime ：2018/10/12 0012 下午 3:19
 * mail : 2726449200@qq.com
 * describe ：外侧3D旋转
 */
public class PageTransformer3D extends BasePageTransformer {
    private float mMaxRotation = 90.0f;
    public PageTransformer3D() {
    }
    public PageTransformer3D(float maxRotation) {
        setMaxRotation(maxRotation);
    }

    //左边  [-1,0]
    @Override
    public void touch2Left(View view, float position) {
        Log.e("TAG","touch2Left========="+position);
        //设置旋转中心点
        view.setPivotX(view.getMeasuredWidth());
        view.setPivotY(view.getMeasuredHeight() * 0.5f);
        view.setRotationY(mMaxRotation*position);
    }

    //从右到左滑动 右边不可见到可见，position -1>0  左边可见到不可见，1>0
    //从左到右滑动，右边可见到不可见 position 0>1,左边不可见到可见，-1>0
    //不可见到可见的从小到大，可见到不可见的从大到小
    @Override
    public void touch2Right(View view, float position) {//[0,1]
        Log.e("TAG","touch2Right========="+position);
        //设置旋转中心点
        view.setPivotX(0);
        view.setPivotY(view.getMeasuredHeight() * 0.5f);
        view.setRotationY(mMaxRotation * position);
    }

    @Override
    public void other(View view, float position) {

    }

    //设置最大旋转
    public void setMaxRotation(float maxRotation) {
        if (maxRotation >= 0.0f && maxRotation <= 90.0f) {
            mMaxRotation = maxRotation;
        }
    }
}
